# -*- coding: utf-8 -*-
"""
API文档定义
"""

# 创建订单接口文档
CREATE_ORDER_DOC = {
    "tags": ["订单管理"],
    "summary": "创建预约订单",
    "description": "用户创建场馆预约订单\n\n**🔐 需要用户Token认证**",
    "security": [{"Bearer": []}],
    "parameters": [
        {
            "name": "body",
            "in": "body",
            "required": True,
            "description": "订单创建参数",
            "schema": {
                "type": "object",
                "required": ["userId", "venueId", "timeSlotId", "reservationDate"],
                "properties": {
                    "userId": {
                        "type": "integer",
                        "description": "用户ID",
                        "example": 1
                    },
                    "venueId": {
                        "type": "integer",
                        "description": "场馆ID",
                        "example": 1
                    },
                    "timeSlotId": {
                        "type": "integer",
                        "description": "时间段ID",
                        "example": 1
                    },
                    "reservationDate": {
                        "type": "string",
                        "description": "预约日期，格式：YYYY-MM-DD",
                        "example": "2024-01-15"
                    },
                    "remark": {
                        "type": "string",
                        "description": "备注信息（可选）",
                        "example": "临时预约"
                    }
                }
            }
        }
    ],
    "responses": {
        "200": {
            "description": "订单创建成功",
            "schema": {
                "type": "object",
                "properties": {
                    "code": {
                        "type": "integer",
                        "example": 200,
                        "description": "状态码"
                    },
                    "message": {
                        "type": "string",
                        "example": "订单创建成功",
                        "description": "响应消息"
                    },
                    "data": {
                        "type": "object",
                        "description": "订单信息",
                        "properties": {
                            "orderId": {
                                "type": "integer",
                                "example": 1,
                                "description": "订单ID"
                            },
                            "orderNo": {
                                "type": "string",
                                "example": "ORD20240115123456789012",
                                "description": "订单号"
                            },
                            "orderInfo": {
                                "type": "object",
                                "description": "订单详细信息",
                                "properties": {
                                    "id": {"type": "integer", "example": 1},
                                    "order_no": {"type": "string", "example": "ORD20240115123456789012"},
                                    "user_id": {"type": "integer", "example": 1},
                                    "venue_id": {"type": "integer", "example": 1},
                                    "time_slot_id": {"type": "integer", "example": 1},
                                    "reservation_date": {"type": "string", "example": "2024-01-15"},
                                    "start_time": {"type": "string", "example": "08:00"},
                                    "end_time": {"type": "string", "example": "10:00"},
                                    "amount": {"type": "number", "example": 100.00},
                                    "status": {"type": "integer", "example": 0},
                                    "status_text": {"type": "string", "example": "未支付"},
                                    "remark": {"type": "string", "example": "临时预约"},
                                    "created_at": {"type": "string", "example": "2024-01-15 08:30:00"}
                                }
                            }
                        }
                    }
                }
            }
        },
        "400": {
            "description": "请求参数错误",
            "schema": {
                "type": "object",
                "properties": {
                    "code": {"type": "integer", "example": 400},
                    "message": {"type": "string", "example": "缺少必要参数"}
                }
            }
        },
        "404": {
            "description": "资源不存在",
            "schema": {
                "type": "object",
                "properties": {
                    "code": {"type": "integer", "example": 404},
                    "message": {"type": "string", "example": "用户不存在"}
                }
            }
        }
    }
}

# 获取订单详情接口文档
GET_ORDER_DETAIL_DOC = {
    "tags": ["订单管理"],
    "summary": "获取订单详情",
    "description": "根据订单ID获取订单详细信息\n\n**🔐 需要用户Token认证**",
    "security": [{"Bearer": []}],
    "parameters": [
        {
            "name": "order_id",
            "in": "path",
            "type": "integer",
            "required": True,
            "description": "订单ID",
            "example": 1
        },
        {
            "name": "userId",
            "in": "query",
            "type": "integer",
            "required": True,
            "description": "用户ID",
            "example": 1
        }
    ],
    "responses": {
        "200": {
            "description": "获取订单详情成功",
            "schema": {
                "type": "object",
                "properties": {
                    "code": {
                        "type": "integer",
                        "example": 200,
                        "description": "状态码"
                    },
                    "message": {
                        "type": "string",
                        "example": "获取成功",
                        "description": "响应消息"
                    },
                    "data": {
                        "type": "object",
                        "description": "订单详细信息",
                        "properties": {
                            "id": {"type": "integer", "example": 1, "description": "订单ID"},
                            "order_no": {"type": "string", "example": "ORD20240115123456789012", "description": "订单号"},
                            "user_id": {"type": "integer", "example": 1, "description": "用户ID"},
                            "venue_id": {"type": "integer", "example": 1, "description": "场馆ID"},
                            "time_slot_id": {"type": "integer", "example": 1, "description": "时间段ID"},
                            "reservation_date": {"type": "string", "example": "2024-01-15", "description": "预约日期"},
                            "start_time": {"type": "string", "example": "08:00", "description": "开始时间"},
                            "end_time": {"type": "string", "example": "10:00", "description": "结束时间"},
                            "amount": {"type": "number", "example": 100.00, "description": "订单金额"},
                            "status": {"type": "integer", "example": 1, "description": "订单状态"},
                            "status_text": {"type": "string", "example": "已支付", "description": "状态文本"},
                            "remark": {"type": "string", "example": "临时预约", "description": "备注"},
                            "checkin_code": {"type": "string", "example": "ABC123", "description": "签到码"},
                            "checkin_time": {"type": "string", "example": "2024-01-15 08:30:00", "description": "签到时间"},
                            "created_at": {"type": "string", "example": "2024-01-15 08:00:00", "description": "创建时间"},
                            "updated_at": {"type": "string", "example": "2024-01-15 08:30:00", "description": "更新时间"},
                            "venue": {
                                "type": "object",
                                "description": "场馆信息",
                                "properties": {
                                    "id": {"type": "integer", "example": 1},
                                    "name": {"type": "string", "example": "中央篮球场"},
                                    "type": {"type": "string", "example": "basketball"},
                                    "address": {"type": "string", "example": "北京市朝阳区体育馆路1号"},
                                    "location": {"type": "string", "example": "北京"}
                                }
                            },
                            "time_slot": {
                                "type": "object",
                                "description": "时间段信息",
                                "properties": {
                                    "id": {"type": "integer", "example": 1},
                                    "day_of_week": {"type": "integer", "example": 1},
                                    "start_time": {"type": "string", "example": "08:00"},
                                    "end_time": {"type": "string", "example": "10:00"},
                                    "price": {"type": "number", "example": 100.00},
                                    "capacity": {"type": "integer", "example": 10}
                                }
                            }
                        }
                    }
                }
            }
        },
        "403": {
            "description": "无权访问",
            "schema": {
                "type": "object",
                "properties": {
                    "code": {"type": "integer", "example": 403},
                    "message": {"type": "string", "example": "无权访问该订单"}
                }
            }
        },
        "404": {
            "description": "订单不存在",
            "schema": {
                "type": "object",
                "properties": {
                    "code": {"type": "integer", "example": 404},
                    "message": {"type": "string", "example": "订单不存在"}
                }
            }
        }
    }
}

# 获取用户订单列表接口文档
GET_USER_ORDERS_DOC = {
    "tags": ["订单管理"],
    "summary": "获取用户订单列表",
    "description": "获取指定用户的订单列表，支持分页和状态筛选\n\n**🔐 需要用户Token认证**",
    "security": [{"Bearer": []}],
    "parameters": [
        {
            "name": "user_id",
            "in": "path",
            "type": "integer",
            "required": True,
            "description": "用户ID",
            "example": 1
        },
        {
            "name": "page",
            "in": "query",
            "type": "integer",
            "required": False,
            "description": "页码，从1开始",
            "example": 1,
            "default": 1
        },
        {
            "name": "perPage",
            "in": "query",
            "type": "integer",
            "required": False,
            "description": "每页数量",
            "example": 10,
            "default": 10
        },
        {
            "name": "status",
            "in": "query",
            "type": "integer",
            "required": False,
            "description": "订单状态筛选：0=未支付，1=已支付，2=已取消，3=已完成，4=已退款",
            "example": 1
        }
    ],
    "responses": {
        "200": {
            "description": "获取订单列表成功",
            "schema": {
                "type": "object",
                "properties": {
                    "code": {
                        "type": "integer",
                        "example": 200,
                        "description": "状态码"
                    },
                    "message": {
                        "type": "string",
                        "example": "获取成功",
                        "description": "响应消息"
                    },
                    "data": {
                        "type": "object",
                        "description": "订单列表数据",
                        "properties": {
                            "total": {"type": "integer", "example": 25, "description": "总记录数"},
                            "pages": {"type": "integer", "example": 3, "description": "总页数"},
                            "page": {"type": "integer", "example": 1, "description": "当前页码"},
                            "perPage": {"type": "integer", "example": 10, "description": "每页数量"},
                            "orders": {
                                "type": "array",
                                "description": "订单列表",
                                "items": {
                                    "type": "object",
                                    "properties": {
                                        "id": {"type": "integer", "example": 1},
                                        "order_no": {"type": "string", "example": "ORD20240115123456789012"},
                                        "user_id": {"type": "integer", "example": 1},
                                        "venue_id": {"type": "integer", "example": 1},
                                        "reservation_date": {"type": "string", "example": "2024-01-15"},
                                        "start_time": {"type": "string", "example": "08:00"},
                                        "end_time": {"type": "string", "example": "10:00"},
                                        "amount": {"type": "number", "example": 100.00},
                                        "status": {"type": "integer", "example": 1},
                                        "status_text": {"type": "string", "example": "已支付"},
                                        "created_at": {"type": "string", "example": "2024-01-15 08:00:00"},
                                        "venue": {
                                            "type": "object",
                                            "properties": {
                                                "id": {"type": "integer", "example": 1},
                                                "name": {"type": "string", "example": "中央篮球场"},
                                                "type": {"type": "string", "example": "basketball"},
                                                "address": {"type": "string", "example": "北京市朝阳区体育馆路1号"}
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

# 取消订单接口文档
CANCEL_ORDER_DOC = {
    "tags": ["订单管理"],
    "summary": "取消订单",
    "description": "用户取消未支付或已支付的订单\n\n**🔐 需要用户Token认证**",
    "security": [{"Bearer": []}],
    "parameters": [
        {
            "name": "order_id",
            "in": "path",
            "type": "integer",
            "required": True,
            "description": "订单ID",
            "example": 1
        },
        {
            "name": "body",
            "in": "body",
            "required": True,
            "description": "取消订单参数",
            "schema": {
                "type": "object",
                "required": ["userId"],
                "properties": {
                    "userId": {
                        "type": "integer",
                        "description": "用户ID",
                        "example": 1
                    },
                    "reason": {
                        "type": "string",
                        "description": "取消原因（可选）",
                        "example": "临时有事"
                    }
                }
            }
        }
    ],
    "responses": {
        "200": {
            "description": "订单取消成功",
            "schema": {
                "type": "object",
                "properties": {
                    "code": {"type": "integer", "example": 200},
                    "message": {"type": "string", "example": "订单已取消"}
                }
            }
        },
        "400": {
            "description": "订单状态不允许取消",
            "schema": {
                "type": "object",
                "properties": {
                    "code": {"type": "integer", "example": 400},
                    "message": {"type": "string", "example": "该订单无法取消"}
                }
            }
        }
    }
}

# 签到接口文档
CHECKIN_ORDER_DOC = {
    "tags": ["订单管理"],
    "summary": "订单签到",
    "description": "用户在预约当天签到确认到场\n\n**🔐 需要用户Token认证**",
    "security": [{"Bearer": []}],
    "parameters": [
        {
            "name": "order_id",
            "in": "path",
            "type": "integer",
            "required": True,
            "description": "订单ID",
            "example": 1
        },
        {
            "name": "body",
            "in": "body",
            "required": True,
            "description": "签到参数",
            "schema": {
                "type": "object",
                "required": ["userId"],
                "properties": {
                    "userId": {
                        "type": "integer",
                        "description": "用户ID",
                        "example": 1
                    }
                }
            }
        }
    ],
    "responses": {
        "200": {
            "description": "签到成功",
            "schema": {
                "type": "object",
                "properties": {
                    "code": {"type": "integer", "example": 200},
                    "message": {"type": "string", "example": "签到成功"},
                    "data": {
                        "type": "object",
                        "properties": {
                            "checkinCode": {"type": "string", "example": "ABC123", "description": "签到码"},
                            "checkinTime": {"type": "string", "example": "2024-01-15 08:30:00", "description": "签到时间"}
                        }
                    }
                }
            }
        },
        "400": {
            "description": "签到失败",
            "schema": {
                "type": "object",
                "properties": {
                    "code": {"type": "integer", "example": 400},
                    "message": {"type": "string", "example": "该订单无法签到"}
                }
            }
        }
    }
}

# 基础文档模板（保持兼容性）
SIMPLE_DOC = {
    "tags": ["订单管理"],
    "summary": "API接口",
    "description": "API接口说明",
    "responses": {
        "200": {
            "description": "请求成功",
            "schema": {
                "type": "object",
                "properties": {
                    "code": {"type": "integer", "example": 200},
                    "message": {"type": "string", "example": "操作成功"},
                    "data": {"type": "object"}
                }
            }
        }
    }
}

# 为兼容性创建通用别名
GET_ORDER_LIST_DOC = SIMPLE_DOC
UPDATE_ORDER_DOC = SIMPLE_DOC
DELETE_ORDER_DOC = SIMPLE_DOC

# 管理员相关
ADMIN_GET_ORDER_LIST_DOC = SIMPLE_DOC
ADMIN_UPDATE_ORDER_DOC = SIMPLE_DOC
ADMIN_DELETE_ORDER_DOC = SIMPLE_DOC
ADMIN_ORDER_STATS_DOC = SIMPLE_DOC

# 活动相关
CREATE_ACTIVITY_DOC = SIMPLE_DOC
GET_ACTIVITY_LIST_DOC = SIMPLE_DOC
GET_ACTIVITY_DETAIL_DOC = SIMPLE_DOC
UPDATE_ACTIVITY_DOC = SIMPLE_DOC
DELETE_ACTIVITY_DOC = SIMPLE_DOC
JOIN_ACTIVITY_DOC = SIMPLE_DOC

# 支付相关
CREATE_PAYMENT_DOC = SIMPLE_DOC
PAYMENT_NOTIFY_DOC = SIMPLE_DOC
GET_PAYMENT_STATUS_DOC = SIMPLE_DOC
QUERY_PAYMENT_DOC = SIMPLE_DOC

# 横幅相关
GET_BANNER_LIST_DOC = {
    "tags": ["横幅管理"],
    "summary": "获取横幅列表",
    "description": "获取系统横幅列表",
    "responses": {
        "200": {
            "description": "获取横幅列表成功",
            "schema": {
                "type": "object",
                "properties": {
                    "code": {"type": "integer", "example": 200},
                    "message": {"type": "string", "example": "获取成功"},
                    "data": {
                        "type": "object",
                        "properties": {
                            "banners": {
                                "type": "array",
                                "items": {
                                    "type": "object",
                                    "properties": {
                                        "id": {"type": "integer", "example": 1, "description": "横幅ID"},
                                        "title": {"type": "string", "example": "新年特惠", "description": "横幅标题"},
                                        "image_url": {"type": "string", "example": "https://example.com/banner1.jpg", "description": "图片URL"},
                                        "link_url": {"type": "string", "example": "https://example.com/promo", "description": "链接URL"},
                                        "sort_order": {"type": "integer", "example": 1, "description": "排序"},
                                        "is_active": {"type": "boolean", "example": True, "description": "是否启用"},
                                        "created_at": {"type": "string", "example": "2024-01-01 12:00:00", "description": "创建时间"}
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

CREATE_BANNER_DOC = {
    "tags": ["横幅管理"],
    "summary": "创建横幅",
    "description": "创建新的横幅",
    "parameters": [
        {
            "name": "body",
            "in": "body",
            "required": True,
            "schema": {
                "type": "object",
                "required": ["title", "image_url"],
                "properties": {
                    "title": {"type": "string", "description": "横幅标题", "example": "新年特惠"},
                    "image_url": {"type": "string", "description": "图片URL", "example": "https://example.com/banner.jpg"},
                    "link_url": {"type": "string", "description": "链接URL", "example": "https://example.com/promo"},
                    "sort_order": {"type": "integer", "description": "排序", "example": 1}
                }
            }
        }
    ],
    "responses": {
        "200": {
            "description": "创建横幅成功",
            "schema": {
                "type": "object",
                "properties": {
                    "code": {"type": "integer", "example": 200},
                    "message": {"type": "string", "example": "横幅创建成功"},
                    "data": {
                        "type": "object",
                        "properties": {
                            "banner_id": {"type": "integer", "example": 1, "description": "横幅ID"}
                        }
                    }
                }
            }
        }
    }
}

UPDATE_BANNER_DOC = {
    "tags": ["横幅管理"],
    "summary": "更新横幅",
    "description": "更新横幅信息",
    "responses": {
        "200": {
            "description": "更新成功",
            "schema": {
                "type": "object",
                "properties": {
                    "code": {"type": "integer", "example": 200},
                    "message": {"type": "string", "example": "横幅更新成功"}
                }
            }
        }
    }
}

DELETE_BANNER_DOC = {
    "tags": ["横幅管理"],
    "summary": "删除横幅",
    "description": "删除横幅",
    "responses": {
        "200": {
            "description": "删除成功",
            "schema": {
                "type": "object",
                "properties": {
                    "code": {"type": "integer", "example": 200},
                    "message": {"type": "string", "example": "横幅删除成功"}
                }
            }
        }
    }
}

# 管理员相关
ADMIN_LOGIN_DOC = SIMPLE_DOC
GET_ADMIN_INFO_DOC = SIMPLE_DOC

# 仪表盘相关
GET_DASHBOARD_STATS_DOC = {
    "tags": ["仪表盘"],
    "summary": "获取仪表盘统计数据",
    "description": "获取系统总体统计数据，包括用户数、订单数、场馆数等",
    "responses": {
        "200": {
            "description": "获取统计数据成功",
            "schema": {
                "type": "object",
                "properties": {
                    "code": {"type": "integer", "example": 200, "description": "状态码"},
                    "message": {"type": "string", "example": "获取成功", "description": "响应消息"},
                    "data": {
                        "type": "object",
                        "description": "统计数据",
                        "properties": {
                            "totalUsers": {"type": "integer", "example": 1250, "description": "总用户数"},
                            "totalOrders": {"type": "integer", "example": 3420, "description": "总订单数"},
                            "totalVenues": {"type": "integer", "example": 25, "description": "总场馆数"},
                            "totalRevenue": {"type": "number", "example": 125600.50, "description": "总收入"},
                            "todayOrders": {"type": "integer", "example": 45, "description": "今日订单数"},
                            "todayRevenue": {"type": "number", "example": 3200.00, "description": "今日收入"}
                        }
                    }
                }
            }
        }
    }
}

GET_REVENUE_CHART_DOC = {
    "tags": ["仪表盘"],
    "summary": "获取收入图表数据",
    "description": "获取指定时间范围内的收入趋势数据",
    "parameters": [
        {
            "name": "period",
            "in": "query",
            "type": "string",
            "required": False,
            "description": "时间周期：7d=最近7天，30d=最近30天，90d=最近90天",
            "example": "30d"
        }
    ],
    "responses": {
        "200": {
            "description": "获取收入图表数据成功",
            "schema": {
                "type": "object",
                "properties": {
                    "code": {"type": "integer", "example": 200},
                    "message": {"type": "string", "example": "获取成功"},
                    "data": {
                        "type": "object",
                        "properties": {
                            "chartData": {
                                "type": "array",
                                "items": {
                                    "type": "object",
                                    "properties": {
                                        "date": {"type": "string", "example": "2024-01-15"},
                                        "revenue": {"type": "number", "example": 2350.00},
                                        "orderCount": {"type": "integer", "example": 35}
                                    }
                                }
                            },
                            "totalRevenue": {"type": "number", "example": 67800.00}
                        }
                    }
                }
            }
        }
    }
}

GET_ORDER_CHART_DOC = {
    "tags": ["仪表盘"],
    "summary": "获取订单图表数据",
    "description": "获取指定时间范围内的订单趋势数据",
    "responses": {
        "200": {
            "description": "获取订单图表数据成功",
            "schema": {
                "type": "object",
                "properties": {
                    "code": {"type": "integer", "example": 200},
                    "message": {"type": "string", "example": "获取成功"},
                    "data": {
                        "type": "object",
                        "properties": {
                            "chartData": {
                                "type": "array",
                                "items": {
                                    "type": "object",
                                    "properties": {
                                        "date": {"type": "string", "example": "2024-01-15"},
                                        "totalOrders": {"type": "integer", "example": 35},
                                        "completedOrders": {"type": "integer", "example": 32}
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

GET_ORDER_TREND_DOC = {
    "tags": ["仪表盘"],
    "summary": "获取订单趋势数据",
    "description": "获取订单趋势分析数据",
    "responses": {
        "200": {
            "description": "获取订单趋势数据成功",
            "schema": {
                "type": "object",
                "properties": {
                    "code": {"type": "integer", "example": 200},
                    "message": {"type": "string", "example": "获取成功"},
                    "data": {
                        "type": "object",
                        "properties": {
                            "trendData": {
                                "type": "array",
                                "items": {
                                    "type": "object",
                                    "properties": {
                                        "period": {"type": "string", "example": "2024-01-15"},
                                        "pending": {"type": "integer", "example": 5},
                                        "paid": {"type": "integer", "example": 28},
                                        "completed": {"type": "integer", "example": 32}
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

# 其他订单相关
REFUND_ORDER_DOC = SIMPLE_DOC

# 场馆管理相关
GET_VENUE_BOOKINGS_DOC = SIMPLE_DOC
ADMIN_GET_VENUES_DOC = SIMPLE_DOC
ADMIN_GET_TIME_SLOTS_DOC = SIMPLE_DOC
